﻿using System.Windows;
using System.Windows.Controls;

namespace Test.Silverlight.DataGrid {
	public partial class Customization : UserControl {
		public Customization() {
			InitializeComponent();
			grid.DataSource = CarsData.DataSource;
		}
		void AgDataGridColumn_PrepareCellDisplayElement(object sender, DevExpress.AgDataGrid.PrepareCellDisplayElementEventArgs e) {
			TextBlock displayElem = (TextBlock)e.DisplayElement;
			displayElem.Text = ((int)e.CellData.CellValue).ToString() + (((string)((Cars)e.CellData.RowValue).TransmissAutomatic) == "Yes" ? "AT" : "MT");
		}
        void OptionsPanel_Loaded(object sender, RoutedEventArgs e) {
            FrameworkElement optionsPanel = (FrameworkElement)sender;
            ((CheckBox)optionsPanel.FindName("cbEvenOddRows")).IsChecked = grid.ChangeOddRowsAppearance;
            ((CheckBox)optionsPanel.FindName("cbShowColumnHeaders")).IsChecked = grid.ShowColumnHeaders == Visibility.Visible;
            ((CheckBox)optionsPanel.FindName("cbShowGroupPanel")).IsChecked = grid.ShowGroupPanel == Visibility.Visible;
            ((CheckBox)optionsPanel.FindName("cbShowTotals")).IsChecked = grid.ShowTotals == Visibility.Visible;
        }

        #region OptionsPanel
        void cbEvenOddRows_Checked(object sender, RoutedEventArgs e) {
            grid.ChangeOddRowsAppearance = ((CheckBox)sender).IsChecked == true;
        }
        void cbShowColumnHeaders_IsCheckedChanged(object sender, RoutedEventArgs e) {
            grid.ShowColumnHeaders = GetVisibilityByIsVisible(((CheckBox)sender).IsChecked == true);
        }
        void cbShowGroupPanel_IsCheckedChanged(object sender, RoutedEventArgs e) {
            grid.ShowGroupPanel = GetVisibilityByIsVisible(((CheckBox)sender).IsChecked == true);
        }
        void cbShowTotals_IsCheckedChanged(object sender, RoutedEventArgs e) {
            grid.ShowTotals = GetVisibilityByIsVisible(((CheckBox)sender).IsChecked == true);
        }
        Visibility GetVisibilityByIsVisible(bool isVisible) {
            return isVisible ? Visibility.Visible : Visibility.Collapsed;
        }
        #endregion
    }
}
